package com.model.dao;

// Generated Sep 14, 2013 1:19:21 AM by Hibernate Tools 4.0.0

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 * Home object for domain model class UserTable.
 * 
 * @see com.model.dao.com.model.dao.UserTable
 * @author Hibernate Tools
 */
@Stateless
public class UserTableHome {

	private static final Log log = LogFactory.getLog(UserTableHome.class);

	@PersistenceContext
	private EntityManager entityManager;

	public void persist(UserTable transientInstance) {
		log.debug("persisting UserTable instance");
		try {
			entityManager.persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void remove(UserTable persistentInstance) {
		log.debug("removing UserTable instance");
		try {
			entityManager.remove(persistentInstance);
			log.debug("remove successful");
		} catch (RuntimeException re) {
			log.error("remove failed", re);
			throw re;
		}
	}

	public UserTable merge(UserTable detachedInstance) {
		log.debug("merging UserTable instance");
		try {
			UserTable result = entityManager.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public UserTable findById(int id) {
		log.debug("getting UserTable instance with id: " + id);
		try {
			UserTable instance = entityManager.find(UserTable.class, id);
			log.debug("get successful");
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public static void main(String[] args) {
		Session session = null;
		Transaction tx = null;
		try {
			session = SessionFactoryUtil.getSessionFactory()
					.getCurrentSession();

			tx = session.beginTransaction();
			UserTable userTable = new UserTable();
			userTable.setArea("Area");
			userTable.setCity("city");
			userTable.setEmail("a@a.com");
			userTable.setHouseno("houseno");
//			userTable.setIduserTable(3);
			userTable.setLandmark("landmark");
			userTable.setMobileno("mobileno10");
			userTable.setName("name");
			userTable.setPassword("password");
			userTable.setStreet("street");
//			 UserTableHome tableHome=new UserTableHome();
//			 UserTable table= (UserTable) session.get(UserTable.class, 1);
//			 UserTable table=tableHome.findById(1);
			
//			 System.out.println(table.getMobileno());
			 session.save(userTable);
				tx.commit();
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
			ex.printStackTrace(System.out);
			if (tx != null) {
				tx.rollback();
			}

		}
	}

	// mysqlconnector
	// slf4j dom4j jbossloggin javaassist hibernate-commons-annotations
	// hibernate-core, jpa jta
}
